package com.zhuj.codec;

import com.zhuj.core.util.SerializerUtil;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * Created by Administrator on 2018/1/8.
 */
public class NrpcProtostuffEncode extends MessageToByteEncoder {

    protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception {
        long a = System.currentTimeMillis();
        byte[] data = SerializerUtil.serialize(msg);
        out.writeInt(data.length);
        out.writeBytes(data);
        System.out.println("编码毫秒数："+(System.currentTimeMillis()-a));
    }

}
